package com.group.nepg.entity;

import static java.lang.Math.max;


 // 创建准确AQI数据的静态工厂

public class AccurateAqiDataFactory {
    /**
     * 创建准确AQI数据的静态方法
     * @param co CO精确数据
     * @param pm PM精确数据
     * @param so2 SO2精确数据
     * @return 根据输入的精确数据计算出的AQI精确数据
     */
    public static AccurateAqiData getAccurateAqiData(double co, double pm, double so2) {
        COLevel coLevel;
        PMLevel pmLevel;
        SO2Level so2Level;
        AccurateAqiLevel accurateAqiLevel;

        if (Double.compare(co, 5) < 0) {
            coLevel = COLevel.CO_LEVEL_1;
        } else if (Double.compare(co, 10) < 0) {
            coLevel = COLevel.CO_LEVEL_2;
        } else if (Double.compare(co, 35) < 0) {
            coLevel = COLevel.CO_LEVEL_3;
        } else if (Double.compare(co, 60) < 0) {
            coLevel = COLevel.CO_LEVEL_4;
        } else if (Double.compare(co, 90) < 0) {
            coLevel = COLevel.CO_LEVEL_5;
        } else {
            coLevel = COLevel.CO_LEVEL_6;
        }

        if (Double.compare(pm, 35) < 0) {
            pmLevel = PMLevel.PM_LEVEL_1;
        } else if (Double.compare(pm, 75) < 0) {
            pmLevel = PMLevel.PM_LEVEL_2;
        } else if (Double.compare(pm, 115) < 0) {
            pmLevel = PMLevel.PM_LEVEL_3;
        } else if (Double.compare(pm, 150) < 0) {
            pmLevel = PMLevel.PM_LEVEL_4;
        } else if (Double.compare(pm, 250) < 0) {
            pmLevel = PMLevel.PM_LEVEL_5;
        } else {
            pmLevel = PMLevel.PM_LEVEL_6;
        }

        if (Double.compare(so2, 50) < 0) {
            so2Level = SO2Level.SO2_LEVEL_1;
        } else if (Double.compare(so2, 150) < 0) {
            so2Level = SO2Level.SO2_LEVEL_2;
        } else if (Double.compare(so2, 475) < 0) {
            so2Level = SO2Level.SO2_LEVEL_3;
        } else if (Double.compare(so2, 800) < 0) {
            so2Level = SO2Level.SO2_LEVEL_4;
        } else if (Double.compare(so2, 1600) < 0) {
            so2Level = SO2Level.SO2_LEVEL_5;
        } else {
            so2Level = SO2Level.SO2_LEVEL_6;
        }

        int maxLevel = max(max(coLevel.ordinal(), pmLevel.ordinal()), so2Level.ordinal());
        accurateAqiLevel = AccurateAqiLevel.values()[maxLevel];

        return new AccurateAqiData(coLevel, pmLevel, so2Level, co, pm, so2, accurateAqiLevel);

    }

}